package com.windy.kafka.trace.config;


import com.windy.kafka.trace.annotation.EnableMQ;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportAware;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;

import java.util.concurrent.Executor;

/**
 * Created by liyufeng on 2022/3/22
 */
@Configuration
public abstract class AbstractSenderConfiguration implements ImportAware {
    @Nullable
    protected AnnotationAttributes enableMQ;

    @Nullable
    protected Executor executor;

    @Nullable
    protected AsyncUncaughtExceptionHandler exceptionHandler;


    @Override
    public void setImportMetadata(AnnotationMetadata importMetadata) {
        this.enableMQ = AnnotationAttributes.fromMap(
                importMetadata.getAnnotationAttributes(EnableMQ.class.getName(), false));
        if (this.enableMQ == null) {
            throw new IllegalArgumentException(
                    "@EnableMQ is not present on importing class " + importMetadata.getClassName());
        }
    }

}
